package com.yizisu.playerlibrary.impl.exoplayer

import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.Player.PlayWhenReadyChangeReason

sealed class PlayerPlaybackState {
    object STATE_IDLE : PlayerPlaybackState()
    object STATE_BUFFERING : PlayerPlaybackState()
    object STATE_READY : PlayerPlaybackState()
    object STATE_ENDED : PlayerPlaybackState()
    object UN_KNOW : PlayerPlaybackState()
}

internal fun getPlayerPlayWhenReady(@PlayWhenReadyChangeReason state: Int): PlayerPlayWhenReady {
    return when (state) {
        Player.PLAY_WHEN_READY_CHANGE_REASON_AUDIO_BECOMING_NOISY -> {
            PlayerPlayWhenReady.AUDIO_BECOMING_NOISY
        }
        Player.PLAY_WHEN_READY_CHANGE_REASON_AUDIO_FOCUS_LOSS -> {
            PlayerPlayWhenReady.AUDIO_FOCUS_LOSS
        }
        Player.PLAY_WHEN_READY_CHANGE_REASON_END_OF_MEDIA_ITEM -> {
            PlayerPlayWhenReady.END_OF_MEDIA_ITEM
        }
        Player.PLAY_WHEN_READY_CHANGE_REASON_REMOTE -> {
            PlayerPlayWhenReady.REMOTE
        }
        Player.PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST -> {
            PlayerPlayWhenReady.USER_REQUEST
        }
        else -> {
            PlayerPlayWhenReady.UN_KNOW
        }
    }
}

sealed class PlayerPlayWhenReady {
    object USER_REQUEST : PlayerPlayWhenReady()
    object AUDIO_FOCUS_LOSS : PlayerPlayWhenReady()
    object AUDIO_BECOMING_NOISY : PlayerPlayWhenReady()
    object REMOTE : PlayerPlayWhenReady()
    object END_OF_MEDIA_ITEM : PlayerPlayWhenReady()
    object UN_KNOW : PlayerPlayWhenReady()
}